package com.codingclub.application.dto;

import com.codingclub.common.enums.ErrCode;
import com.codingclub.common.exception.BusinessException;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

@Data
public class SubjectLabelDTO {
    private static final long serialVersionUID = -81300902549330938L;
    /**
     * 主键
     */
    private Long id;
    /**
     * 标签分类
     */
    private String labelName;
    /**
     * 排序
     */
    private Integer sortNum;

    private String categoryId;

    public void validatorParam(SubjectLabelDTO dto, boolean isAdd) {
        if(dto==null){
            throw new BusinessException(ErrCode.PARAMS_ERROR);
        }
        if(StringUtils.isBlank(dto.getLabelName())||dto.getSortNum()==null){
            throw new BusinessException(ErrCode.PARAMS_ERROR);
        }
        if(isAdd&&dto.getCategoryId()==null){
            throw new BusinessException(ErrCode.PARAMS_ERROR);
        }
        if(!isAdd && dto.getId()==null){
            throw new BusinessException(ErrCode.PARAMS_ERROR);
        }
    }

    public void validatorQueryParam(SubjectLabelDTO subjectLabelDTO) {
        if(subjectLabelDTO==null&&subjectLabelDTO.getCategoryId()==null){
            throw new BusinessException(ErrCode.PARAMS_ERROR);
        }
    }
}
